<script setup lang="ts">
import { onBeforeRouteUpdate, useRoute, useRouter } from 'vue-router'
import { ref, reactive, computed, onMounted, toRefs } from 'vue';
import { showNotify, showToast } from 'vant';
import { default as http, getImageUrl } from '@/utils/request.js';
const router = useRouter(); //获取到 router 对象，用于编程式跳转导航
const route = useRoute();   //获取路由对象
function toAddReturn() {
    router.push("/addreorder");
}

//地址列表
const onClickLeft = () => history.back();
// 折叠面板
const activeNames = ref(['1']);

//h
//route.params.xxx 获取路径参数
console.log('reorderId = ', route.params.reorderId);
// const props = defineProps(['re', 'title']);
// onBeforeRouteUpdate((to, from ) => {
//     console.log("onBeforeRouteUpdate!!!!",to.params.orderNumber)
//     if(to.params.orderNumber !== from.params.orderNumber){
//         // console.log("这里可以请求服务器获取id = ",props.ordernumber)
//     }
// })

const orderInfo = reactive({
    reorderId:'',
    sellerName: '',
    amount: '',
    orderNumber: '',
    createTime: '',
    details: '',
    goodsName: '',
    orderPrice: '',
    reason: '',
    moneyBackTime: '',
    sellerOpinion: '',
    returnWay: '',
    returnStatus: '',
    picture: '',
    retrackingNumber: '',//物流单号
})
// 获取订单详情
const getOrderInfo = () => {
    console.log("------------订单详情");
    http.get('/user/returnorder/reorderId/' + route.params.reorderId).then((res) => {
        console.log("========数据加载：", res.data.data);

        orderInfo.reason = res.data.data.reason;
        orderInfo.moneyBackTime = res.data.data.moneyBackTime;
        orderInfo.sellerName = res.data.data.sellerName;
        orderInfo.amount = res.data.data.amount;
        orderInfo.orderNumber = res.data.data.orderNumber;
        orderInfo.details = res.data.data.details;
        orderInfo.goodsName = res.data.data.goodsName;
        orderInfo.orderPrice = res.data.data.orderPrice;
        orderInfo.sellerOpinion = res.data.data.sellerOpinion;
        orderInfo.picture = res.data.data.picture;
        orderInfo.retrackingNumber = res.data.data.retrackingNumber;
        orderInfo.returnStatus = res.data.data.returnStatus;
        orderInfo.createTime = res.data.data.createTime;
        orderInfo.returnWay = res.data.data.returnWay;
        orderInfo.reorderId = res.data.data.reorderId;
        console.log("物流单号:", orderInfo.retrackingNumber);

        // resolve(); // 当获取待收货列表成功后，返回一个解析成功的Promise  
    }).catch(err => {
        //   reject(err); // 当请求失败时，返回一个请求失败的Promise  
    });

}

const onFailed = () => {
        showNotify({ type: 'success', message: '通知内容' });
    }
const inputButton = ref(true);

// isSuccess()

// 如果商家同意则添加物流单号
const addTrackNumber = () => {

    console.log("商家意见:",orderInfo.sellerOpinion);
    if (String(orderInfo.sellerOpinion )==='同意') {
        console.log("商家意见:",orderInfo.sellerOpinion);
        console.log("orderInfo:",orderInfo.retrackingNumber);
        const reorder = orderInfo;
        reorder.retrackingNumber = orderInfo.retrackingNumber;
        inputButton.value = false;
        console.log("禁用键值：",inputButton.value)
        console.log("f方法外的reorder:",reorder);
        http.put("/user/returnorder/Tracking", reorder, { headers: { 'Content-Type': 'application/json' } })
            .then((res) => {
                console.log("f方法 里的reorder:",reorder);
                console.log('!!!!!!!!!!!!!!!!!返回值：', res.data);
                const { code, message } = res.data;
                console.log("=========code", code);
                if (200 === code) {
                    showNotify({ type: 'success', message: '提交成功' });
                } else {
                    showNotify({ type: 'danger', message });
                }
            }).catch((err) => {
                console.log('评论失败：', err);
            });
    } else {
        showNotify({ type: 'danger', message: '商家未同意' });
    }
    const onFailed = () => {
        showNotify({ type: 'success', message: '通知内容' });
    }

}



onMounted(() => {
    getOrderInfo();
    // addTrackNumber();
    // handleDelete(); 
    // 获取个人信息  

     
});
</script >


<template>
    <van-col class="nav_bar">
        <van-nav-bar title="订单详情" left-text="返回" :fixed="true" left-arrow @click-left="onClickLeft" />
    </van-col>
    <!-- </header> -->
    <div style="margin-top: 30px;">

    </div>
    <div style="width: 350px; margin-top: 10px">

        <van-cell-group inset style="width: 350px;">
            <van-cell>
                <van-row style="margin-left: 8px;">
                    <van-col>
                        <div>订单状态：{{ orderInfo.returnStatus }}</div>
                    </van-col>
                </van-row>
            </van-cell>
            <van-cell>
                <van-row style="margin-left: 8px;">
                    <van-col>
                        <div>退货申请时间：{{ orderInfo.createTime }}</div>
                    </van-col>
                </van-row>
            </van-cell>


            <van-cell>
                <div style="width:300px; color: #c8d175; margin-top: 10px;">
                    <van-card :num=orderInfo.amount :price=orderInfo.orderPrice :desc=orderInfo.details
                        :title=orderInfo.details :thumb="getImageUrl(orderInfo.picture)" size="large">
                        <template #tags>
                            <van-tag plain type="primary" style="flex-grow: 1; margin-right: 10px;">{{ orderInfo.goodsName
                            }}</van-tag>
                        </template>

                    </van-card>
                </div>
            </van-cell>
            <van-cell>
                <van-row style="margin-left: 8px;">
                    <van-col>
                        <div>商品总价：{{ orderInfo.orderPrice }}</div>
                    </van-col>
                </van-row>
            </van-cell>
            <van-cell>
                <van-row style="margin-left: 8px;">
                    <van-col>
                        <div>实付款：{{ orderInfo.orderPrice }}</div>
                    </van-col>
                </van-row>
            </van-cell>
            <van-cell>
                <van-row style="margin-left: 8px;">
                    <van-row>
                        <div>订单编号：{{ orderInfo.orderNumber }}</div>
                    </van-row>
                </van-row>
            </van-cell>
            <van-cell>
                <van-row style="margin-left: 8px;">
                    <van-row>
                        <div>退回方式：{{ orderInfo.returnWay }}</div>
                    </van-row>
                </van-row>
            </van-cell>

            <van-cell>
                <van-row style="margin-left: 8px;">
                    <van-col>
                        <div>商家意见：{{ orderInfo.sellerOpinion }}</div>
                    </van-col>
                </van-row>
            </van-cell>

            <van-cell>
                <van-row style="margin-left: 10px;">
                    <van-col>
                        <div>物流单号：{{ orderInfo.retrackingNumber }}</div>
                    </van-col>
                </van-row>
            </van-cell>

            <van-cell>
                <van-row style="margin-left: 8px;">
                    <van-row>
                        <div>退款时间：{{ orderInfo.moneyBackTime }}</div>
                    </van-row>
                </van-row>
            </van-cell>
            <van-cell>
                <van-row style="margin-left: -7px;">
                    <van-col>
                        <van-field v-model="orderInfo.retrackingNumber" center clearable :disabled="inputButton" label="物流单号"
                            placeholder="请输入物流单号"></van-field>
                    </van-col>
                </van-row>
                <van-row>
                    <van-button @click="addTrackNumber">提交</van-button>
                </van-row>
            </van-cell>
        </van-cell-group>



        <!-- <van-row style="margin-left: 10px;">
                
            </van-row> -->

    </div>
    <br>

    <RouterView />
</template>

<style scoped>
.nav_bar {
    position: relative;
    top: -32px;
    /* left:-32px;
    right: -32px; */
    margin: 0px -32px
}

header {
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 9999;
    line-height: 1.5;
    max-height: 100vh;
}


header {
    line-height: 1.5;
    max-height: 100vh;
}


nav {
    width: 100%;
    font-size: 12px;
    text-align: center;
    margin-top: 2rem;
}

nav a.router-link-exact-active {
    color: var(--color-text);
}

nav a.router-link-exact-active:hover {
    background-color: transparent;
}

nav a {
    display: inline-block;
    padding: 0 1rem;
    border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
    border: 0;
}

@media (min-width: 1024px) {
    header {
        display: flex;
        place-items: center;
        padding-right: calc(var(--section-gap) / 2);
    }


    header .wrapper {
        display: flex;
        place-items: flex-start;
        flex-wrap: wrap;
    }

    nav {
        text-align: left;
        margin-left: -1rem;
        font-size: 1rem;
        padding: 1rem 0;
        margin-top: 1rem;
    }
}

.van-field {
    /* 调整每一行边距 */
    padding: 16px 15px;
}

.van-nav-bar {
    color: #d4e09f;
    width: 100%;
}

.full-width-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 10px;
    /* 根据需要调整 */
}

.template {
    background-color: #F0F8FF;
}

.container {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    /* 如果需要垂直居中 */
}

.full-width-button {
    flex: 1;
    /* 使按钮填充整个容器的宽度 */
}

.body {
    background-color: #e2e3df;
}

.img-icon {
    height: 20px;
}

.nav_bar {
    position: relative;
    top: -32px;
    /* left:-32px;
    right: -32px; */
    margin: 2px -32px
}
</style>
